﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Model;
using TaxiDispatchClient.Service;

namespace TaxiDispatchClient
{
    public partial class ReceCallForm : DevExpress.XtraEditors.XtraForm
    {
        public ReceCallForm()
        {
            InitializeComponent();
        }
        private  int _x;//当前窗体X坐标
        private int _y;
        private void ReceCallForm_Load(object sender, EventArgs e)
        {
            this.TopMost = true;
            _x = Screen.PrimaryScreen.WorkingArea.Width - Width;
            _y = Screen.PrimaryScreen.WorkingArea.Height-Height;
            Location = new Point(this._x, this._y);
            //this.Visible = false;
        }

        private void btn_answer_Click(object sender, EventArgs e)
        {
            try
            {
                MainForm.PhoneModem.AnswerThePhone();
                Model.CallRecordsInfo model = new CallRecordsInfo();
                model.Type = 0;
                btn_break.Enabled = true;
                btn_answer.Enabled = false;
            }
            catch (Exception ex)
            {
                Common.CommonRoutine.HandlingExceptions(ex);
            }
        }

        private void btn_break_Click(object sender, EventArgs e)
        {
            Close();
        }

        public void ShowPhoneNumber(string phoneNumber)
        {
            label_phoneNumber.Text = phoneNumber;
            if (MainForm.BlackListOfPsg.Contains(phoneNumber))
            {
                label_warming.Visible = true;
            }
            else
            {
                label_warming.Visible = false;
            }
        }

        private void ReceCallForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (btn_answer.Enabled == false)
                {
                    MainForm.PhoneModem.HangUp();
                }
            }
            catch (Exception ex)
            {
                Common.CommonRoutine.HandlingExceptions(ex);             
            }            
        }

        #region 窗体控件效果
        Point _mouseOff;
        bool _leftFlag;
        private void Form_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _mouseOff = new Point(-e.X, -e.Y);
                _leftFlag = true;
            }
        }

        private void Form_MouseMove(object sender, MouseEventArgs e)
        {
            if (_leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(_mouseOff.X, _mouseOff.Y);
                Location = mouseSet;
            }
        }

        private void Form_MouseUp(object sender, MouseEventArgs e)
        {
            if (_leftFlag)
            {
                _leftFlag = false;
            }
        }

        private void pictureEdit_exit_MouseHover(object sender, EventArgs e)
        {
            pictureBox1.Image = Properties.Resources.snedSmsexit;
            Cursor = Cursors.Hand;
        }

        private void pictureEdit_exit_MouseLeave(object sender, EventArgs e)
        {
            pictureBox1.Image = Properties.Resources.snedSmsexitPressDown;

            Cursor = Cursors.Arrow;

        }
        private void btn_MouseHover(object sender, EventArgs e)
        {
            Cursor = Cursors.Hand;
        }

        private void btn_MouseLeave(object sender, EventArgs e)
        {
            Cursor = Cursors.Arrow;
        }

        private void pictureEdit_exit_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void PhoneUserForm_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Close();
            }
        }
        #endregion
    }
}